package com.yh.autobio.modules.adatper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yh.autobio.R;
import com.yh.autobio.gddb.gdbean.MatBean;

import java.util.ArrayList;

/**
 * Created by imyar on 2016/5/3 0031.
 */
public class RK_NewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private ArrayList<MatBean> workInfos;

    public ArrayList<MatBean> getWorkInfos() {
        return workInfos;
    }

    public RK_NewAdapter(Context context, ArrayList<MatBean> workInfos) {
        mContext = context;
        this.workInfos = workInfos;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new WorkEntryViewHolder(
                LayoutInflater.from(mContext).inflate(R.layout.item_sale_out, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof WorkEntryViewHolder) {
//            try {
//                for (int i = 0; i < workInfos.size(); i++) {
//                    //s.subString(s.length-3,s.length);
//                    //第一个参数是开始截取的位置，第二个是结束位置。
//                    final CKComp mDate = workInfos.get(i);
//                    ((WorkEntryViewHolder) holder).mClock[i].setText(
//                            mDate.getItemDN());
//                    ((WorkEntryViewHolder) holder).mTemp[i].setText(mDate.getCount() + "");
//                    if (mDate.isAll()) {
//                        ((WorkEntryViewHolder) holder).mHumidity[i].setText(
//                                mDate.getCount() + "");
//                        mDate.setChecked(true);
//                        ((WorkEntryViewHolder) holder).mWind[i].setChecked(true);
//                    } else {
//                        ((WorkEntryViewHolder) holder).mHumidity[i].setText(
//                                mDate.getCurrentcount() + "");
//                        ((WorkEntryViewHolder) holder).mWind[i].setChecked(false);
//                        mDate.setChecked(false);
//                    }
//
//                    ((WorkEntryViewHolder) holder).mWind[i].setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//                        @Override
//                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                            mDate.setChecked(isChecked);
//                        }
//                    });
//                }
//            } catch (Exception e) {
//                //Snackbar.make(holder.itemView, R.string.api_error, Snackbar.LENGTH_SHORT).show();
//                PLog.e(TAG, e.toString());
//            }
        }
    }

    @Override
    public int getItemCount() {
        return workInfos.size();
    }

    /**
     * 工序详情
     */
    class WorkEntryViewHolder extends RecyclerView.ViewHolder {
//        private LinearLayout itemHourInfoLinearlayout;
//        private TextView[] mClock = new TextView[workInfos.size()];
//        private TextView[] mTemp = new TextView[workInfos.size()];
//        private TextView[] mHumidity = new TextView[workInfos.size()];
//        private CheckBox[] mWind = new CheckBox[workInfos.size()];


        public WorkEntryViewHolder(View itemView) {
            super(itemView);
//            itemHourInfoLinearlayout = (LinearLayout) itemView.findViewById(R.id.item_hour_info_linearlayout);
//
//            for (int i = 0; i < workInfos.size(); i++) {
//                View view = View.inflate(mContext, R.layout.item_rk_line_new, null);
//                mClock[i] = (TextView) view.findViewById(R.id.one_clock);
//                mTemp[i] = (TextView) view.findViewById(R.id.one_temp);
//                mHumidity[i] = (TextView) view.findViewById(R.id.one_humidity);
//                mWind[i] = (CheckBox) view.findViewById(R.id.one_wind);
//                mWind[i].setEnabled(false);
//                itemHourInfoLinearlayout.addView(view);
//            }
        }
    }
}
